#include "StdAfx.h"
#include "Vector4.h"
#include "Matrix44.h"

VAMPIRE_NAMESPACE_BEGIN

Vector4::Vector4( const Real& x, const Real& y, const Real& z, const Real& w )
{
	mData.w = w;
	mData.x = x;
	mData.y = y;
	mData.z = z;
}

Vampire::Vector4 Vector4::operator+( const Vector4& rhs ) const
{
	return Vector4(mData + rhs.mData);
}

Vampire::Vector4 Vector4::operator+() const
{
	return *this;
}

Vampire::Vector4 Vector4::operator-( const Vector4& rhs ) const
{
	return Vector4(mData - rhs.mData);
}

Vampire::Vector4 Vector4::operator*( const Real& rhs ) const
{
	return Vector4(mData * rhs);
}

Vampire::Vector4 Vector4::operator/( const Real& rhs ) const
{
	return Vector4(mData / rhs);
}

Vector4& Vector4::operator+=( const Vector4& rhs )
{
	mData += rhs.mData;
	return *this;
}

Vector4& Vector4::operator-=( const Vector4& rhs )
{
	mData -= rhs.mData;
	return *this;
}

Vector4& Vector4::operator*=( const Real& rhs )
{
	mData *= rhs;
	return *this;
}

Vector4& Vector4::operator/=( const Real& rhs )
{
	mData /= rhs;
	return *this;
}

void Vector4::operator=( const Vector4& rhs )
{
	mData = rhs.mData;
}

void Vector4::operator=( const D3DXVECTOR4& rhs )
{
	mData = rhs;
}

bool Vector4::operator==( const Vector4& rhs ) const
{
	return mData == rhs.mData ? true : false;
}

bool Vector4::operator!=( const Vector4& rhs ) const
{
	return mData == rhs.mData ? false : true;
}

Vampire::Vector4 Vector4::operator-() const
{
	return Vector4(-mData);
}

Vampire::Vector4 Vector4::getMassCenter( const Vector4 triangle[3], Real factor1, Real factor2 ) const
{
	Vector4 result;
	D3DXVec4BaryCentric(&(result.mData), &(triangle[0].mData), &(triangle[1].mData), &(triangle[2].mData), factor1, factor2);
	return result;
}

Vampire::Real Vector4::dot( const Vector4& rhs ) const
{
	return D3DXVec4Dot(&(mData), &(rhs.mData));
}

void Vector4::normalise()
{
	D3DXVec4Normalize(&(mData), &(mData));
}

Vampire::Real Vector4::length() const
{
	return D3DXVec4Length(&(mData));
}

Vampire::Real Vector4::lengthSqrt() const
{
	return D3DXVec4LengthSq(&(mData));
}

Vampire::Vector4 Vector4::add( const Vector4& other ) const
{
	Vector4 sum;
	D3DXVec4Add(&(sum.mData), &mData, &(other.mData));
	return sum;
}

Vampire::Vector4 Vector4::subtract( const Vector4& other ) const
{
	Vector4 difference;
	D3DXVec4Subtract(&(difference.mData), &mData, &(other.mData));
	return difference;
}

void Vector4::transform( const Matrix44& matrix )
{
	D3DXVec4Transform(&mData, &mData, &(matrix.mData));
}

void Vector4::scale( const Real& s )
{
	D3DXVec4Scale(&mData, &mData, s);
}

const Vector4 Vector4::ZERO(0.0f, 0.0f, 0.0f, 0.0f);

VAMPIRE_NAMESPACE_END
